<template>
<div class="mytable">
  <!-- <span>{{ this.$store.state.dialog.show }}</span> -->
    <el-table :data="tableData"  
    border 
    show-summary
    :summary-method="getSummaries"
    >
            <el-table-column
      type="index"
      width="50">
    </el-table-column>
            <el-table-column v-for="(item,key) in tableKey"

            :key="key"

            :prop="item.value"

            :label="item.name"
            sortable
            ></el-table-column>
           
    </el-table>

</div>
 
</template>

<script>
export default {
  name: "simpletable",

  data() {
    return {};
  },
  methods: {
      getSummaries(param) {
        const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          // console.log(column.label)
          // if (column.label.includes('数量') ) {
          //   console.log('包含qty')
          // }
          if (!values.every(value => isNaN(value))) {
            if (column.label.includes('数量')) {
              
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] += ' ';
            }
          } else {
            sums[index] = '';
          }
        });

        return sums;
      }
    },
  props: ["tableData", "tableKey"],
};
</script>

<style lang="scss" module>
</style>